package com.yunhe.abnormal.config;

import com.yunhe.abnormal.websocket.AlarmNotifyHandler;
import com.yunhe.abnormal.websocket.AlarmCountHandler;
import com.yunhe.abnormal.websocket.AlarmOverviewHandler;
import com.yunhe.abnormal.websocket.AlarmTopLevelHandler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

/**
 * WebSocket配置类
 * @author liuronglei
 */
@Configuration
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {
    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
//        registry.addHandler(abnormalRealtimeHandler(), "/alarmEvents/realtime/socket")
//                .setAllowedOrigins("*");
        registry.addHandler(abnormalRealtimeCountHandler(), "/alarmEvents/realtimeCount/socket")
                .setAllowedOrigins("*");
        registry.addHandler(abnormalSeriousCountHandler(), "/alarmEvents/highestLevel/socket")
                .setAllowedOrigins("*");
        registry.addHandler(abnormalNotifyRealTimeHandler(), "/alarmEvents/realTimeNotify/socket")
                .setAllowedOrigins("*");
        registry.addHandler(abnormalRealtimeOverviewHandler(), "/alarmEvents/realtime/overview/socket")
                .setAllowedOrigins("*");
    }

//    @Bean
//    public WebSocketHandler abnormalRealtimeHandler() {
//        return new AbnormalRealtimeHandler();
//    }

    @Bean
    public WebSocketHandler abnormalRealtimeCountHandler() {
        return new AlarmCountHandler();
    }

    @Bean
    public WebSocketHandler abnormalSeriousCountHandler() { return new AlarmTopLevelHandler(); }

    @Bean
    public WebSocketHandler abnormalRealtimeOverviewHandler() { return new AlarmOverviewHandler(); }

    @Bean
    public WebSocketHandler abnormalNotifyRealTimeHandler() { return new AlarmNotifyHandler(); }
}